<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>字典添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all" />
    <link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_1041315_7utpmi3q5g4.css">
    <style type="text/css">
        .layui-form-item .layui-inline{ width:33.333%; float:left; margin-right:0; }
        @media(max-width:1240px){
            .layui-form-item .layui-inline{ width:100%; float:none; }
        }
        .layui-form-item .role-box {
            position: relative;
        }
        .layui-form-item .role-box .jq-role-inline {
            height: 100%;
            overflow: auto;
        }

    </style>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <div class="layui-form-item">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
            <legend style="font-size:16px;">字典信息</legend>
        </fieldset>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block " >
            <input type="text" name="type" id="HandoverCompany" class="layui-input" style="position:absolute;z-index:2;width:85%;" lay-verify="required"onkeyup="search()" autocomplete="off">
            <select lay-verify="required" id="type" lay-filter="type" lay-search="">
                <option th:each="type:${types}"
                th:value="${type}" th:text="${type}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">值</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="value" lay-verify="required" placeholder="请输入值">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="sort" lay-verify="required" placeholder="请输入排序值">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="description" class="layui-textarea" placeholder="可以输入该标签描述"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addDict"><i class="iconfont icon-fabu"></i>立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary"><i class="iconfont icon-zhongzhi"></i>重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="/layui/layui.js"></script>
<script>
    layui.config({
        base: '/js/common/' //假设这是你存放拓展模块的根目录
    }).use(['form','jquery','layer','common'],function(){
       var form = layui.form,
           $    = layui.jquery,
           common = layui.common,
        layer = layui.layer;
        form.on('select(type)', function (data) {   //选择移交单位 赋值给input框
            $("#HandoverCompany").val(data.value);
            $("#type").next().find("dl").css({ "display": "none" });
            form.render();
        });
        window.search = function () {
            var value = $("#HandoverCompany").val();
            $("#type").val(value);
            form.render();
            $("#type").next().find("dl").css({ "display": "block" });
            var dl = $("#type").next().find("dl").children();
            var j = -1;
            for (var i = 0; i < dl.length; i++) {
                if (dl[i].innerHTML.indexOf(value) <= -1) {
                    dl[i].style.display = "none";
                    j++;
                }
                if (j == dl.length-1) {
                    $("#type").next().find("dl").css({ "display": "none" });
                }
            }

        }
        form.on("submit(addDict)",function(data){
            $("#HandoverCompany").val(data.value);
            var saveLoading = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            $.post("add",data.field,function(res){
                if(res.success){
                    top.layer.close(saveLoading);
                    common.cmsLaySucMsg("添加成功！");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭                        //刷新父页面
                    parent.location.reload();
                }else{
                    top.layer.close(saveLoading);
                    common.cmsLayErrorMsg(res.message);
                }
            });
            return false;
        });

    });
</script>
</body>
</html>